<?php

/**
 * SegmentedFeaturedOffer.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Selling Partner API for Pricing.
 *
 * The Selling Partner API for Pricing helps you programmatically retrieve product pricing and offer pricing information for Amazon Marketplace products.  For more information, refer to the [Product Pricing v2022-05-01 Use Case Guide](https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-use-case-guide).
 *
 * The version of the OpenAPI document: 2022-05-01
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\pricing\v2022_05_01;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * SegmentedFeaturedOffer Class Doc Comment.
 *
 * @category Class
 *
 * @description A product offer with segment information indicating where it&#39;s featured.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class SegmentedFeaturedOffer implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    public const SUB_CONDITION__NEW = 'New';
    public const SUB_CONDITION_MINT = 'Mint';
    public const SUB_CONDITION_VERY_GOOD = 'VeryGood';
    public const SUB_CONDITION_GOOD = 'Good';
    public const SUB_CONDITION_ACCEPTABLE = 'Acceptable';
    public const SUB_CONDITION_POOR = 'Poor';
    public const SUB_CONDITION_CLUB = 'Club';
    public const SUB_CONDITION_OEM = 'OEM';
    public const SUB_CONDITION_WARRANTY = 'Warranty';
    public const SUB_CONDITION_REFURBISHED_WARRANTY = 'RefurbishedWarranty';
    public const SUB_CONDITION_REFURBISHED = 'Refurbished';
    public const SUB_CONDITION_OPEN_BOX = 'OpenBox';
    public const SUB_CONDITION_OTHER = 'Other';

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'SegmentedFeaturedOffer';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'seller_id' => 'string',
        'condition' => '\SpApi\Model\pricing\v2022_05_01\Condition',
        'sub_condition' => 'string',
        'fulfillment_type' => '\SpApi\Model\pricing\v2022_05_01\FulfillmentType',
        'listing_price' => '\SpApi\Model\pricing\v2022_05_01\MoneyType',
        'shipping_options' => '\SpApi\Model\pricing\v2022_05_01\ShippingOption[]',
        'points' => '\SpApi\Model\pricing\v2022_05_01\Points',
        'prime_details' => '\SpApi\Model\pricing\v2022_05_01\PrimeDetails',
        'featured_offer_segments' => '\SpApi\Model\pricing\v2022_05_01\FeaturedOfferSegment[]'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'seller_id' => null,
        'condition' => null,
        'sub_condition' => null,
        'fulfillment_type' => null,
        'listing_price' => null,
        'shipping_options' => null,
        'points' => null,
        'prime_details' => null,
        'featured_offer_segments' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'seller_id' => false,
        'condition' => false,
        'sub_condition' => true,
        'fulfillment_type' => false,
        'listing_price' => false,
        'shipping_options' => true,
        'points' => true,
        'prime_details' => true,
        'featured_offer_segments' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'seller_id' => 'sellerId',
        'condition' => 'condition',
        'sub_condition' => 'subCondition',
        'fulfillment_type' => 'fulfillmentType',
        'listing_price' => 'listingPrice',
        'shipping_options' => 'shippingOptions',
        'points' => 'points',
        'prime_details' => 'primeDetails',
        'featured_offer_segments' => 'featuredOfferSegments',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'seller_id' => 'setSellerId',
        'condition' => 'setCondition',
        'sub_condition' => 'setSubCondition',
        'fulfillment_type' => 'setFulfillmentType',
        'listing_price' => 'setListingPrice',
        'shipping_options' => 'setShippingOptions',
        'points' => 'setPoints',
        'prime_details' => 'setPrimeDetails',
        'featured_offer_segments' => 'setFeaturedOfferSegments',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'seller_id' => 'getSellerId',
        'condition' => 'getCondition',
        'sub_condition' => 'getSubCondition',
        'fulfillment_type' => 'getFulfillmentType',
        'listing_price' => 'getListingPrice',
        'shipping_options' => 'getShippingOptions',
        'points' => 'getPoints',
        'prime_details' => 'getPrimeDetails',
        'featured_offer_segments' => 'getFeaturedOfferSegments',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('seller_id', $data ?? [], null);
        $this->setIfExists('condition', $data ?? [], null);
        $this->setIfExists('sub_condition', $data ?? [], null);
        $this->setIfExists('fulfillment_type', $data ?? [], null);
        $this->setIfExists('listing_price', $data ?? [], null);
        $this->setIfExists('shipping_options', $data ?? [], null);
        $this->setIfExists('points', $data ?? [], null);
        $this->setIfExists('prime_details', $data ?? [], null);
        $this->setIfExists('featured_offer_segments', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Gets allowable values of the enum.
     *
     * @return string[]
     */
    public function getSubConditionAllowableValues(): array
    {
        return [
            self::SUB_CONDITION__NEW,
            self::SUB_CONDITION_MINT,
            self::SUB_CONDITION_VERY_GOOD,
            self::SUB_CONDITION_GOOD,
            self::SUB_CONDITION_ACCEPTABLE,
            self::SUB_CONDITION_POOR,
            self::SUB_CONDITION_CLUB,
            self::SUB_CONDITION_OEM,
            self::SUB_CONDITION_WARRANTY,
            self::SUB_CONDITION_REFURBISHED_WARRANTY,
            self::SUB_CONDITION_REFURBISHED,
            self::SUB_CONDITION_OPEN_BOX,
            self::SUB_CONDITION_OTHER,
        ];
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['seller_id']) {
            $invalidProperties[] = "'seller_id' can't be null";
        }
        if (null === $this->container['condition']) {
            $invalidProperties[] = "'condition' can't be null";
        }
        $allowedValues = $this->getSubConditionAllowableValues();
        if (!is_null($this->container['sub_condition']) && !in_array($this->container['sub_condition'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'sub_condition', must be one of '%s'",
                $this->container['sub_condition'],
                implode("', '", $allowedValues)
            );
        }

        if (null === $this->container['fulfillment_type']) {
            $invalidProperties[] = "'fulfillment_type' can't be null";
        }
        if (null === $this->container['listing_price']) {
            $invalidProperties[] = "'listing_price' can't be null";
        }
        if (null === $this->container['featured_offer_segments']) {
            $invalidProperties[] = "'featured_offer_segments' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets seller_id.
     */
    public function getSellerId(): string
    {
        return $this->container['seller_id'];
    }

    /**
     * Sets seller_id.
     *
     * @param string $seller_id the seller identifier for the offer
     */
    public function setSellerId(string $seller_id): self
    {
        if (is_null($seller_id)) {
            throw new \InvalidArgumentException('non-nullable seller_id cannot be null');
        }
        $this->container['seller_id'] = $seller_id;

        return $this;
    }

    /**
     * Gets condition.
     */
    public function getCondition(): string
    {
        return $this->container['condition'];
    }

    /**
     * Sets condition.
     *
     * @param string $condition condition
     */
    public function setCondition(string $condition): self
    {
        if (is_null($condition)) {
            throw new \InvalidArgumentException('non-nullable condition cannot be null');
        }
        $this->container['condition'] = $condition;

        return $this;
    }

    /**
     * Gets sub_condition.
     */
    public function getSubCondition(): ?string
    {
        return $this->container['sub_condition'];
    }

    /**
     * Sets sub_condition.
     *
     * @param null|string $sub_condition the item subcondition of the offer
     */
    public function setSubCondition(?string $sub_condition): self
    {
        if (is_null($sub_condition)) {
            array_push($this->openAPINullablesSetToNull, 'sub_condition');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('sub_condition', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $allowedValues = $this->getSubConditionAllowableValues();
        if (!is_null($sub_condition) && !in_array($sub_condition, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'sub_condition', must be one of '%s'",
                    $sub_condition,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['sub_condition'] = $sub_condition;

        return $this;
    }

    /**
     * Gets fulfillment_type.
     */
    public function getFulfillmentType(): string
    {
        return $this->container['fulfillment_type'];
    }

    /**
     * Sets fulfillment_type.
     *
     * @param string $fulfillment_type fulfillment_type
     */
    public function setFulfillmentType(string $fulfillment_type): self
    {
        if (is_null($fulfillment_type)) {
            throw new \InvalidArgumentException('non-nullable fulfillment_type cannot be null');
        }
        $this->container['fulfillment_type'] = $fulfillment_type;

        return $this;
    }

    /**
     * Gets listing_price.
     */
    public function getListingPrice(): MoneyType
    {
        return $this->container['listing_price'];
    }

    /**
     * Sets listing_price.
     *
     * @param MoneyType $listing_price listing_price
     */
    public function setListingPrice(MoneyType $listing_price): self
    {
        if (is_null($listing_price)) {
            throw new \InvalidArgumentException('non-nullable listing_price cannot be null');
        }
        $this->container['listing_price'] = $listing_price;

        return $this;
    }

    /**
     * Gets shipping_options.
     */
    public function getShippingOptions(): ?array
    {
        return $this->container['shipping_options'];
    }

    /**
     * Sets shipping_options.
     *
     * @param null|array $shipping_options A list of shipping options associated with this offer
     */
    public function setShippingOptions(?array $shipping_options): self
    {
        if (is_null($shipping_options)) {
            array_push($this->openAPINullablesSetToNull, 'shipping_options');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('shipping_options', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['shipping_options'] = $shipping_options;

        return $this;
    }

    /**
     * Gets points.
     */
    public function getPoints(): ?Points
    {
        return $this->container['points'];
    }

    /**
     * Sets points.
     *
     * @param null|Points $points points
     */
    public function setPoints(?Points $points): self
    {
        if (is_null($points)) {
            array_push($this->openAPINullablesSetToNull, 'points');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('points', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['points'] = $points;

        return $this;
    }

    /**
     * Gets prime_details.
     */
    public function getPrimeDetails(): ?PrimeDetails
    {
        return $this->container['prime_details'];
    }

    /**
     * Sets prime_details.
     *
     * @param null|PrimeDetails $prime_details prime_details
     */
    public function setPrimeDetails(?PrimeDetails $prime_details): self
    {
        if (is_null($prime_details)) {
            array_push($this->openAPINullablesSetToNull, 'prime_details');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('prime_details', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['prime_details'] = $prime_details;

        return $this;
    }

    /**
     * Gets featured_offer_segments.
     */
    public function getFeaturedOfferSegments(): array
    {
        return $this->container['featured_offer_segments'];
    }

    /**
     * Sets featured_offer_segments.
     *
     * @param array $featured_offer_segments the list of segment information in which the offer is featured
     */
    public function setFeaturedOfferSegments(array $featured_offer_segments): self
    {
        if (is_null($featured_offer_segments)) {
            throw new \InvalidArgumentException('non-nullable featured_offer_segments cannot be null');
        }
        $this->container['featured_offer_segments'] = $featured_offer_segments;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
